package com.zw.yzk.kabu.utils;

import android.content.Context;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Created by zhanwei on 2017/7/8.
 */

public class AppUtils {

    /**
     * 弹出输入法软键盘
     *
     * @param v
     */
    public static void popupSoftKeyboard(final EditText v) {
        if (v == null) {
            return;
        }
        try {
            InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(v, InputMethodManager.HIDE_NOT_ALWAYS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 隐藏软键盘
     *
     * @param v
     */
    public static void HideKeyboard(EditText v) {
        if (v == null) {
            return;
        }
        try {
            InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm.isActive()) {
                imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
